<?php
/**
 * Fend Framework
 * [Gimoo!] (C)2006-2009 Gimoo Inc. (http://fend.gimoo.net)
 *
 * 获取头像路径
 * {f_pic gid=$uid tp='s' fp=1}
 *
 * @Package GimooFend
 * @Support http://bbs.gimoo.net
 * @Author  Gimoo <gimoohr@gmail.com>
 * @version $Id: function.f_pic.php 142 2014-08-10 15:05:35Z gimoo $
 * @param   $params
**/

function smarty_function_f_pic($pars)
{
    static $tps=array('s'=>'_small.jpg','m'=>'_middle.jpg','b'=>'_big.jpg');
    $tp=empty($pars['tp']) ? 's' : $pars['tp'];
    $tmp='nopic'.$tps[$tp];
    if(isset($pars['uid'])){//000/010/37.jpg
        $pars['uid']=str_pad($pars['uid'],8,0,STR_PAD_LEFT);
        $tmp=preg_replace("/^(\d{3})(\d{3})(\d{2,})/i","user/\\1/\\2/\\3",$pars['uid']).$tps[$tp];
    }elseif(isset($pars['gid'])){
        $pars['gid']=str_pad($pars['gid'],8,0,STR_PAD_LEFT);
        $tmp=preg_replace("/^(\d{2})(\d{2})(\d{2})(\d{2})/i","group/\\1/\\2/\\3/\\4".$tps[$tp],$pars['gid']);
    }
    empty($pars['fp']) && $tmp=$GLOBALS['_dm']['fs'].$tmp;
    return $tmp;
}
?>
